<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>
			商品添加
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="./css/x-admin.css" media="all">
		<link rel="stylesheet" href="css/jquery.mobile.min.css" />
		<link href="css/xtiper.css" type="text/css" rel="stylesheet" />
		<script src="js/xtiper.min.js" type="text/javascript"></script>
	</head>

	<body>
		<div onclick="turn()">
			<img src="images/返回.png" style="width: 30;" height="30">
		</div>
		<div class="x-body">
			<div class="layui-form-item">
				<label class="layui-form-label">
                        <span class="x-red">*</span>登录账号
                    </label>
				<div class="layui-input-inline">
					<input type="text" id="userEntername" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
                        <span class="x-red">*</span>密码
                    </label>
				<div class="layui-input-inline">
					<input type="text" id="userPwd" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
                        <span class="x-red">*</span>手机号码
                    </label>
				<div class="layui-input-inline">
					<input type="text" id="userNumber" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">
                        <span class="x-red">*</span>用户名称
                    </label>
				<div class="layui-input-inline">
					<input type="text" id="userName" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">
                    </label>
				<div onclick="save()">
					<button class="layui-btn"> 保存 </button>
				</div>
			</div>
		</div>
		<script src="./lib/layui/layui.js" charset="utf-8">
		</script>
		<script src="./js/x-layui.js" charset="utf-8">
		</script>
		<script src="js/jquery.min.js"></script>

		<script type="text/javascript">
			function save() {
				if($("#userNumber").val() == "") {
					xtip.msg('手机号为空！');
				} else if($("#userPwd").val() == "") {
					xtip.msg('密码未填！');
				} else if($("#userName").val() == "") {
					xtip.msg('用户名称为空！');
				} else if($("#userEntername").val() == "") {
					xtip.msg('账号为空！');
				} else {
					var url = "http://localhost:8080/user/insert";
					var settings = {
						"url": url,
						"method": "POST",
						"timeout": 0,
						"headers": {
							"Content-Type": "application/json"
						},
						"data": JSON.stringify({
							"userName": $("#userName").val(),
							"userEntername": $("#userEntername").val(),
							"userPwd": $("#userPwd").val(),
							"userNumber": $("#userNumber").val()
						}),
					};
					$.ajax(settings).done(function(response) {
						if(response==1){
							xtip.msg('添加成功！');
							location.href = "./admin-list.html";
						}else{
							xtip.msg('添加失败，已存在相同账号！');
						}
					});
				}
			}
		</script>

		<script>
			function turn() {
				location.href = "./admin-list.html";
			}
		</script>
	</body>

</html>